/*
 Copyright (C) 2008  Maurizio Monticelli

 This program is free software; you can redistribute it and/or modify it under the terms of the 
 GNU General Public License as published by the Free Software Foundation; either version 2 of the 
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 
 Public License for more details.

 You should have received a copy of the GNU General Public License along with this program; if not, write 
 to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 
*/


package ch.justdoit;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.Menu.Item;
import ch.justdoit.andriodrpncalc.model.Model;
import ch.justdoit.andriodrpncalc.view.MainView;


public class androidrpncalc extends Activity {
//    @Override
//	public boolean onKeyDown(int keyCode, KeyEvent event) {
//		boolean result = false;
//		result = super.onKeyDown(keyCode, event);
//		return true;
//	}


	/** Called when the activity is first created. */
	
	public Model model;
	private MainView mainView;
	public static final String VERSION = "0.1";
	public static final int CREDITS_ID = Menu.FIRST;
	public static final int SETTINGS_ID = Menu.FIRST + 1;
	private static final int ACTIVITY_CREDITS = 0;
	private static final int ACTIVITY_SETTINGS = 1;
	
    
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        //setTheme(android.R.style.Theme_Black);
        setTitle(getTitle() + " v" + VERSION);
		
        model = Model.getInstance();
        
		mainView = new MainView(this, model);
		
		
		setContentView(mainView);
	
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        boolean result = super.onCreateOptionsMenu(menu);
        //return mainView.initMenu(menu);
        
        menu.add(0, SETTINGS_ID, "Settings");
        menu.add(0, CREDITS_ID, "Credits");
        return result;
    }


    @Override
    public boolean onOptionsItemSelected(Item item) {
        switch (item.getId()) {
        case CREDITS_ID:
            showCredits();
            break;
        case SETTINGS_ID:
        	showSettings();
        	break;
        }
       
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, String data, Bundle extras) {
        super.onActivityResult(requestCode, resultCode, data, extras);
        model.stack.refeshStack();
    }

	private void showSettings() {
		Intent i = new Intent(this, SettingsView.class);
        startSubActivity(i, ACTIVITY_SETTINGS);
		
	}


	private void showCredits() {
		Intent i = new Intent(this, CreditsView.class);
        startSubActivity(i, ACTIVITY_CREDITS);
		
	}


	
	

}


